<template>
  <div class="contioner">
    <div ref="myChart" :style="{ width: '100%', height: '100%' }"></div>
  </div>
</template>
      
  <script lang="ts" setup>
import * as echarts from 'echarts'
import { Message } from '@arco-design/web-vue'
import { ref, reactive, onMounted, watch } from 'vue'
//引入封装post
import { post } from '@/api/http'
import dayjs from 'dayjs'
//getlist初始化接口参数
let query: any = reactive({
  beginDate: dayjs().format('YYYY'),
    planOrderCode: localStorage.getItem('firmId') || '',
  departmentIds: [],
})
let state: any = null
window.addEventListener('resize', updateChartSize)
function updateChartSize() {
  state.resize()
}
const option: any = ref({
  title: {
    text: '班组产量',
  },
  tooltip: {
    trigger: 'axis',
  },
  legend: {
    data: [],
  },
  grid: {
    left: '3%',
    right: '4%',
    bottom: '3%',
    containLabel: true,
  },
  xAxis: {
    type: 'category',
    boundaryGap: false,
    data: [],
    axisLabel: {
      inside: false,
      padding: [5, 0, 0, -5], //文字左右定位
    },
  },
  yAxis: {
    type: 'value',
  },
  series: [
    {
      name: '当日',
      type: 'line',
      stack: 'Total',
      data: [],
    },
  ],
})

//初始化
onMounted(async () => {
  selectJt()
    // state = states()
  // state.setOption(option.value)
})
const myChart: any = ref()
const states = () => {
  return echarts.init(myChart.value)
}
function selectJt() {
  post({
    url: 'qms/report/departmentOutputReport',
    data: {
      firmId: query.planOrderCode,
      year: Number(query.beginDate),
      departmentIds: query.departmentIds,
    },
  })
    .then((res: any) => {
      if (res.code == 200) {
        state = states()
        option.value.xAxis.data = res.data.mouthList.map((res: any) => {
          return res.split('-')[1]
        })
        Object.keys(res.data.lineData).forEach((o: any, i: any) => {
          option.value.series[i] = {
            name: o,
            type: 'line',
            stack: 'Total',
            data: res.data.lineData[o].map((res: any) => {
              return res.outputByMonth
            }),
            label: { show: true, position: 'top', distance: 10, fontSize: 16 },
            symbolSize: 12,
            lineStyle: {
              width: 2,
            },
          }
        })
        state.setOption(option.value)
      } else {
        Message.error(res.message)
      }
    })
    .finally(() => {})
}
</script>
  <script lang="ts">
export default defineComponent({
  name: 'AttritionRateChart',
})
</script>
  <style scoped>
.contioner {
  width: 100%;
  height: 100%;
  background: #fff;
  padding: 10px;
}

:deep(.ag-cell) {
  border-right: 1px solid #dde2eb;
}

:deep(.ag-header-cell) {
  border-right: 1px solid #dde2eb;
}

:deep(.ag-cell-value) {
  user-select: initial;
  -moz-user-select: text;
  -ms-user-select: text;
  -webkit-user-select: text;
}
</style>
      